<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>菜品类别编辑</title>
    <link href="https://cdn.bootcss.com/twitter-bootstrap/3.0.1/css/bootstrap.css" rel="stylesheet">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <i th:replace="~{common :: baseUrl}"></i>
</head>
<body>
<form class="layui-form" action=""  lay-filter="example">



    <div class="container">
        <div class="row clearfix">
            <div class="col-md-6 column">



                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 100px">员工名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" id="name"  lay-verify="required"  class="layui-input">
                        </div>
                    </div>
                </div>


                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 100px">员工照片</label>
                        <div class="layui-input-inline">
                            <div class="layui-upload">

                                <div class="layui-upload-list">
                                    <input hidden name="photograph" id="picPath1" >
                                    <img width="100px" height="100px" class="layui-upload-img" name="showPic" id="showPic1" >
                                    <p id="uploadText1"></p>
                                </div>
                                <button type="button" class="layui-btn" id="uploadPic1">上传照片</button>
                            </div>
                        </div>
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: 100px">性别</label>
                    <div class="layui-input-block">
                        <input type="radio" name="sex" value="1" title="男" checked>
                        <input type="radio" name="sex" value="0" title="女" >
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 100px">年龄</label>
                        <div class="layui-input-inline">
                            <input type="text" name="age" id="age"  lay-verify="number"  class="layui-input">
                        </div>
                    </div>
                </div>


                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 100px">员工职位</label>
                        <div class="layui-input-inline">
                            <input type="text" name="position" id="position" lay-verify="required"  class="layui-input">
                        </div>
                    </div>
                </div>

                <div class="layui-form">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label" style="width: 100px">出生日期</label>
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input"  name="birthday" id="birthday"  placeholder="yyyy-MM-dd">
                            </div>
                        </div>
                    </div>
                </div>


            </div>
            <div class="col-md-6 column">


                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 100px">头像</label>
                        <div class="layui-input-inline">
                            <div class="layui-upload">

                                <div class="layui-upload-list">
                                    <input hidden name="headPortrait" id="picPath2">
                                    <img width="100px" height="100px" class="layui-upload-img" name="showPic" id="showPic2" >
                                    <p id="uploadText2"></p>
                                </div>
                                <button type="button" class="layui-btn" id="uploadPic2">上传头像</button>
                            </div>
                        </div>
                    </div>
                </div>



                <div class="layui-form-item">

                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 100px">手机号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="phone" id="phone"  class="layui-input" lay-verify="phone"  >
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">

                    <div class="layui-inline">
                        <label class="layui-form-label" style="width: 100px">身份证号</label>
                        <div class="layui-input-inline">
                            <input type="text" name="idCard" id="idCard"  class="layui-input" lay-verify="identity"  >
                        </div>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: 100px">员工状态</label>
                    <div class="layui-input-block">
                        <input type="radio" name="status" value="1" title="在职" >
                        <input type="radio" name="status" value="0" title="离职" >
                    </div>
                </div>



                <div class="layui-form-item">
                    <label class="layui-form-label" style="width: 100px">所在店铺</label>
                    <div class="layui-input-inline">
                        <select name="merchantsId" id="merchantsId" lay-verify="required"  disabled >
                            <option th:each="f : ${merchantsInformationList}"  th:value="${f.id}" th:text="${f.name}" th:selected="${merchantsId eq f.id}"></option>
                        </select>
                    </div>
                </div>

            </div>
        </div>
    </div>



    <div class="layui-form-item" align="center">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="sub">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>

</form>



</body>
<script th:src="@{/layui/layui.js}"></script>
<script th:inline="none">
    //JavaScript代码区域
    layui.use(['element','form','upload','layer','laydate'], function() {
        var element = layui.element;
        var form = layui.form;
        var upload = layui.upload;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var $ = layui.$;

        //常规用法
        laydate.render({
            elem: '#birthday'
        });


        //图片上传
        var uploadInst = upload.render({
            elem: '#uploadPic1'
            ,url: baseUrl+'upload/pic'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#showPic1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code != 0){
                    return layer.msg('上传失败');
                }else {
                    $("#picPath1").val(res.data.src)
                }
                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#uploadText1');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });


        //图片上传
        var uploadInst = upload.render({
            elem: '#uploadPic2'
            ,url: baseUrl+'upload/pic'
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#showPic2').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code != 0){
                    return layer.msg('上传失败');
                }else {
                    $("#picPath2").val(res.data.src)
                }
                //上传成功
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#uploadText2');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });






        //提交
        form.on('submit(sub)', function(data){

            //发送ajax请求  编辑APP信息
            $.ajax({
                url:baseUrl+"shop/assistant/add",
                data:data.field,
                type:"post",
                dataType:"json",
                success:function (result) {
                    if (result.code==0){
                        layer.open({
                            title: '添加员工信息'
                            ,content: '添加成功！'
                            ,end:function () {
                                //当你在iframe页面关闭自身时
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                            }
                        });
                    }else {
                        layer.open({
                            title: '编辑菜品分类信息'
                            ,content: result.msg
                        });
                    }
                },
                error:function () {
                    layer.msg("服务器原地爆炸,请联系管理员!!!");
                }
            })
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。

        });





    });

</script>
</html>